<?php
declare (strict_types = 1);

namespace app\shop\controller;

use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;
use app\common\service\SystemConfigService\Transit\TransitTemplateService;
use app\BaseShopController;
use think\Request;
/**
 * @Group("TransitTemplate")
 * @Middleware({shopMiddileware::class})
 */
class TransitTemplate extends BaseShopController
{
    /**
     * 获取运费模板列表(分页)
     * @Route("getListByPage",method="GET")
     * @return string
     */
    public function getListByPage()
    {
        $result = callApi(TransitTemplateService::class, 'getListByPage',$this->_all_data);
        return apiResponse($result);
    }
    
    /**
     * 获取运费模板列表(不分页)
     * @Route("getListNoPage",method="GET")
     * @return string
     */
    public function getListNoPage()
    {
        $result = callApi(TransitTemplateService::class, 'getListNoPage',$this->_all_data);
        return apiResponse($result);
    }
    

    /**
     * 新增运费模板
     * @Route("addTemplate",method="POST")
     * @return void
     */
    public function addTemplate(){
        $result = callApi(TransitTemplateService::class, 'addTemplate',$this->_all_data);
        if($result['code']==\app\Normal::SUC){
            $this->log(['content'=>'新增运费模板【'.$this->_all_data['name'].'】信息','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 修改运费模板
     * @Route("editTemplate",method="PUT")
     * @return void
     */
    public function editTemplate(){
        $result = callApi(TransitTemplateService::class, 'addTemplate',$this->_all_data);
        if($result['code']==\app\Normal::SUC){
            $this->log(['content'=>'修改运费模板id为【'.$this->_all_data['id'].'】信息','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 获取运费模板id
     * @Route("TemplateInfo/:id",method="GET")
     * @return void
     */
    public function TemplateInfo($id){       
        $param=[
            'id'=>$id,
            'cid'=> $this->_master_user['cid'],
            'cb_id'=> $this->_master_user['cb_id']
        ];
        $result = callApi(TransitTemplateService::class, 'TemplateInfo',$param);
        return apiResponse($result);
    }

    /**
     * 设默认模板
     * @Route("changedefault",method="PUT")
     * @return void
     */
    public function changedefault(){
        $result = callApi(TransitTemplateService::class, 'changedefault',$this->_all_data);
        if($result['code']==\app\Normal::SUC){
            $this->log(['content'=>'设置默认运费模板id【'.$this->_all_data['id'].'】信息','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 删除运费模板
     * @Route("delTemplate/:id",method="DELETE")
     * @return void
     */
    public function delTemplate(){
        $result = callApi(TransitTemplateService::class, 'delTemplate',$this->_all_data);
        if($result['code']==\app\Normal::SUC){
            $this->log(['content'=>'删除运费模板id【'.$this->_all_data['id'].'】信息','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
}